﻿function searchKeyword(obj, formId) {
  //去除前后空格
  var keywordValue = obj.innerHTML.replace(/(^\s*)|(\s*$)/g, "");
  if (keywordValue != "") {
    var formObj = document.getElementById(formId);
    formObj.kw.value = keywordValue;
    formObj.sf.value = 1;
    formObj.st.value = "0";
    if(formObj.pn){
    	formObj.pn.value = "0";
  	}
    formObj.sc.value = "00";
    formObj.submit();
  }
}

function checkForm(obj) {
  var obj = document.getElementById("isearch");
  
  //去除前后空格
  var keywordValue = obj.kw.value.replace(/(^\s*)|(\s*$)/g, "");
  
  if (keywordValue == "" || keywordValue == "请输入关键字") {
    alert("请输入关键字");
    obj.kw.value = "";
    obj.kw.focus();
    return false;
  } else {
  	if(obj.keyword){
	  	var lastKeywordValue = obj.keyword.value.replace(/(^\s*)|(\s*$)/g, "");
	  	if(keywordValue != lastKeywordValue){
	  		clearPageNo();
	  	}
  	}
    obj.kw.value = keywordValue;
    return true;
  }
 
}

function clearKeyword(obj) {
  var keywordValue = obj.value.replace(/(^\s*)|(\s*$)/g, "");
  if (keywordValue == "请输入关键字") {
    obj.value = "";
  }
}

function switchKeywordType(obj, stype) {
	var sclass_1;
	var sclass_2;
	var sclass_3;
	var objname = obj.id;
	var searchField = 1;
	if(stype == 'kt'){
		sclass_1 = 'res_kt_bg1';
		sclass_2 = 'res_kt_bg2';
		sclass_3 = 'res_kt_bg3';
	}else if(stype == 'it'){
		sclass_1 = 'it_bg1';
		sclass_2 = 'it_bg2';
		sclass_3 = 'it_bg3';
	}else if(stype == 'xs'){
		sclass_1 = 'xy_bg1';
		sclass_2 = 'xy_bg2';
		sclass_3 = 'xy_bg3';
	}else if(stype == 'adv'){
		sclass_1 = 'adv_bg1';
		sclass_2 = 'adv_bg2';
		sclass_3 = 'adv_bg3';
	}else if(stype == 'train'){
		sclass_1 = 'train_bg1';
		sclass_2 = 'train_bg2';
		sclass_3 = 'train_bg3';
	}

	if(objname == 'keyword_type_all'){
		document.getElementById('keyword_type_all').className = sclass_2;
		document.getElementById('keyword_type_title').className = sclass_3;
		document.getElementById('keyword_type_author').className = sclass_3;
		searchField = 1;
	}
	
	if(objname == 'keyword_type_title'){
		document.getElementById('keyword_type_all').className = sclass_1;
		document.getElementById('keyword_type_title').className = sclass_2;
		document.getElementById('keyword_type_author').className = sclass_3;
		searchField = 2;
	}
	
	if(objname == 'keyword_type_author'){
		document.getElementById('keyword_type_all').className = sclass_1;
		document.getElementById('keyword_type_title').className = sclass_1;
		document.getElementById('keyword_type_author').className = sclass_2;
		searchField = 3;
	}
	
  document.getElementById("isearch").sf.value = searchField;
  //如果搜索框里有关键字，则切换时马上搜索
  var objForm = document.getElementById("isearch");
  //去除前后空格
  var keywordValue = objForm.kw.value.replace(/(^\s*)|(\s*$)/g, "");
  if (keywordValue != "" && keywordValue != "请输入关键字" && objForm.pn) {
  	gotoPage(0);
	}
}

function clearPageNo() {
  var obj = document.getElementById("isearch");
  if(obj.pn){
  	obj.pn.value = "0";
	}
  return true;
}

function gotoPage(pageNo){
	var formObj = document.getElementById("isearch");
	//去除前后空格
  var keywordValue = formObj.kw.value.replace(/(^\s*)|(\s*$)/g, "");
  var lastKeywordValue = formObj.keyword.value.replace(/(^\s*)|(\s*$)/g, "");
  if (keywordValue == "" || keywordValue == "请输入关键字") {
    alert("请输入关键字");
    formObj.kw.value = "";
    formObj.kw.focus();
    return false;
  }
	if(parseInt(pageNo)>=0){
		if(formObj.pn){
			if(lastKeywordValue == keywordValue){
				formObj.pn.value = parseInt(pageNo);
			} else {
    		formObj.pn.value = "0";
    	}
  	}
	}
	formObj.submit();
}